/**
 * 博客相关类型定义
 */

// 基础类型
export type ID = string | number
export type Timestamp = string | number | Date

// 文章状态
export type ArticleStatus = 'draft' | 'published' | 'archived' | 'deleted'

// API 响应格式
export interface ApiResponse<T = unknown> {
  code: number
  message: string
  data: T
  timestamp?: string
}

export interface PaginatedApiResponse<T = unknown> extends ApiResponse<T[]> {
  pagination: Pagination
}

// 分页信息
export interface Pagination {
  page: number
  limit: number
  total: number
  totalPages: number
  hasNext: boolean
  hasPrev: boolean
}

// 查询参数
export interface QueryParams {
  page?: number
  limit?: number
  sort?: string
  order?: 'asc' | 'desc'
  search?: string
}

// 文章查询参数
export interface ArticleQueryParams extends QueryParams {
  category?: string
  tag?: string
  status?: ArticleStatus
  featured?: boolean
  author?: string
  dateFrom?: string
  dateTo?: string
}

// 搜索参数
export interface ArticleSearchParams extends QueryParams {
  keyword?: string
  category?: string
  tag?: string
  author?: string
}

// 分类
export interface Category {
  id: ID
  name: string
  slug: string
  description?: string
  color?: string
  articleCount: number
  createdAt: Timestamp
  updatedAt: Timestamp
}

// 标签
export interface Tag {
  id: ID
  name: string
  slug: string
  description?: string
  color?: string
  articleCount: number
  createdAt: Timestamp
  updatedAt: Timestamp
}

// 文章
export interface Article {
  id: ID
  title: string
  slug: string
  excerpt?: string
  content: string // Markdown 原始内容
  htmlContent?: string // HTML 渲染内容（用于目录生成）
  coverImage?: string
  status: ArticleStatus
  featured: boolean
  publishDate?: Timestamp
  createdAt: Timestamp
  updatedAt: Timestamp
  category: Category
  tags: Tag[]
  author: {
    id: ID
    name: string
    avatar?: string
  }
  viewCount: number
  likeCount: number
  commentCount: number
  readTime: number
  seo?: {
    title?: string
    description?: string
    keywords?: string[]
  }
}

// 文章列表响应
export type ArticleListResponse = PaginatedApiResponse<Article>

// 搜索结果
export interface SearchResult {
  id: ID
  title: string
  slug: string
  excerpt?: string
  type: 'article' | 'page' | 'category' | 'tag'
  url: string
  relevance: number
}

// 搜索响应
export type SearchResponse = PaginatedResponse<SearchResult>

// 归档项
export interface ArchiveItem {
  year: number
  month: number
  count: number
  articles: Array<{
    id: ID
    title: string
    slug: string
    publishDate: Timestamp
  }>
}

// 博客统计
export interface BlogStats {
  totalArticles: number
  totalCategories: number
  totalTags: number
  totalComments: number
  totalViews: number
  totalLikes: number
  publishedArticles: number
  draftArticles: number
  featuredArticles: number
}
